﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <link href="/View_Mobile/Frozenui1.3/css/frozen.css" rel="stylesheet" />
    <script src="/View_Mobile/JS/layer/layer.m.js"></script>
    <script src="/View_Mobile/JS/zepto.min.js"></script>
    <script src="/View_Mobile/Frozenui1.3/js/frozen.js"></script>
    <script src="/View_Mobile/JS/avalon.mobile.min.js"></script>
    <script src="/View_Mobile/JS/ComFunJS.js?jsver=20160425"></script>
    <script src="/View_Mobile/JS/mobiscroll.zepto.js"></script>
    <script src="/View_Mobile/JS/mobiscroll.core.js"></script>
    <script src="/View_Mobile/JS/mobiscroll.scroller.js"></script>
    <script src="/View_Mobile/JS/mobiscroll.datetime.js"></script>
    <script src="/View_Mobile/JS/mobiscroll.i18n.zh.js"></script>
    <link href="/View_Mobile/JS/Date/FT_Date.min.css" rel="stylesheet" />
    <script src="/View_Mobile/JS/jquery.autoTextarea.js"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script>
        //document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        //    //隐藏右上角按钮
        //    WeixinJSBridge.call('hideOptionMenu');
        //});

        var un = ComFunJS.getCookie("wxusername");

        var fheight = 0;
        var fwidth = 0;
        var strId = "";//会议ID
        //加载时间
        var currYear = (new Date()).getFullYear();
        var opt = {
            date: { preset: 'date' },
            defaultopi: {
                theme: 'android-ics light', //皮肤样式
                display: 'modal', //显示方式
                mode: 'scroller', //日期选择模式
                lang: 'zh',
                startYear: currYear - 5, //开始年份
                endYear: currYear + 5, //结束年份
                onSelect: function (valueText, inst) {
                    //model.ctData.RBDate = valueText;
                }
            }
        };
        function fun1(str) {
            $("#djsj").scroller($.extend(opt['date'], opt['defaultopi'])).scroller('setDate', str, true);//登记时间
        }
        function fun2(str) {
            $(".wcsj").scroller($.extend(opt['date'], opt['defaultopi'])).scroller('setDate', str, true);//完成时间
        }

        var model = avalon.define({
            $id: "rwmodel",
            code: "RWGL",//模块code
            wximg: "",//微信上传图片
            lbData:[],//类别数据
            ctData: { "RWTitle": "", "LeiBie": "", "RWContent": "", "RWFZR": un, "RWCYR": "", "IsTX": "" },//总任务对象

            mxList: [],//子任务列表
            savedata: function () {
                if (model.ctData.RWFZR == "") {
                    $.tips({
                        content: "督办人不能为空",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                if (model.ctData.LeiBie == "") {
                    $.tips({
                        content: "请选择督办类别",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                if (model.ctData.RWTitle == "") {
                    $.tips({
                        content: "请输入任务总标题",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                if (model.ctData.RWCYR == "") {
                    $.tips({
                        content: "请选择负责人",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                var bl = true;
                $(model.mxList).each(function (index, ele) {
                    if (!ele.RWContent)
                    {
                        bl = false;
                        return;
                    }

                });
                if (!bl)
                {
                    $.tips({
                        content: "请确认任务内容是否完整",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                

                    var lg = $.loading({
                        content: '保存中...',
                    })

                    //model.ctData.Files = "";
                    //$("#imglist .tpli").each(function () {
                    //    if ($(this).hasClass("wximg")) { //微信上传未处理的图片
                    //        if (model.wximg) {
                    //            model.wximg += ",";
                    //        }
                    //        model.wximg += $(this).attr("itemid");

                    //    } else {
                    //        if (model.ctData.Files) {
                    //            model.ctData.Files = model.ctData.Files + ',' + $(this).attr("itemid");
                    //        }
                    //        else {
                    //            model.ctData.Files = $(this).attr("itemid");
                    //        }
                    //    }

                    //})
                    $.post("/API/VIEWAPI.ashx?Action=DBRW_ADDCUS_SWRWGL&r=" + Math.random(), { "P1": JSON.stringify(model.ctData.$model), P2: JSON.stringify(model.mxList) }, function (data) {
                        lg.hide();
                        var data = $.parseJSON(data);
                        if (data.ErrorMsg == "") {
                            $("button").hide();
                            var el = $.tips({
                                content: "保存成功！",
                                stayTime: 2000,
                                type: "success"
                            })
                            el.on("tips:hide", function () {
                                //window.location.reload();
                                window.location.replace(location.href);
                            })
                        }
                        else {
                            lg.hide();
                            $.tips({
                                content: "保存失败，原因：" + data.ErrorMsg,
                                stayTime: 2000,
                                type: "warn"
                            })
                        }
                    })
                

            },
            selperson: function () {//显示人员列表
                fzcy = $(this);
                $("#content").hide();
                if (fzcy.attr("id") == "rw_fzry") {
                    $("#iframef").attr("src", "/View_Mobile/UI/UI_PERSON.html?r=" + Math.random()+ "&Users=" + model.ctData.RWCYR);
                    $("#iframef").show();

                    var cheight = fheight;
                    var cwidth = fwidth;

                    $("#iframef").css("height", cheight);
                    $("#iframef").css("width", cwidth);
                }
            },
            fzrw: function (el)
            {
                var rwglitem = { "RWEDate": "", "RWContent": "", "RWUSER": "" };
                rwglitem.RWUSER = el.RWUSER;
                rwglitem.RWEDate = el.RWEDate;
                rwglitem.RWContent = el.RWContent;
                model.mxList.push(rwglitem);
            }

        });

        var fzcy = "";
        //人员取消事件
        function goback() {
            $("#content").show();
            $("#iframef").hide();
        }
        //人员确认事件
        function goconfirm(json) {
            if (json != null) {
                fzcy.removeClass("ui-txt-muted");
                fzcy.html(json.vuser);
                if (fzcy.attr("id") == "rw_fzry") {
                    model.ctData.RWCYR = json.vusername;
                }
            }
            else {
                fzcy.addClass("ui-txt-muted");
                if (fzcy.attr("id") == "rw_fzry") {
                    fzcy.html('请选择负责人');
                    model.ctData.RWCYR = '';
                }
            }

            $("#content").show();
            $("#iframef").hide();
            if (model.ctData.RWCYR) {
                var rwglitem = { "RWEDate": "", "RWContent": "", "RWUSER": "" };
                $(model.mxList).each(function (inx, mxsj) {
                    var bl = true;
                    $(model.ctData.RWCYR.split(',')).each(function (index, ele) {
                        if (ele == mxsj.RWUSER) {
                            bl = false;
                        }
                    });
                    if (bl) { model.mxList.remove(mxsj); }
                });
                $(model.ctData.RWCYR.split(',')).each(function (index, ele) {
                    var bl=true;
                    $(model.mxList).each(function (inx, mxsj) {
                        if (ele == mxsj.RWUSER) {
                            bl = false;
                        }
                    });
                    if (bl) {
                        rwglitem.RWUSER = ele;
                        rwglitem.RWEDate = ComFunJS.getnowdate();
                        model.mxList.push(rwglitem);
                    }
                });
                
                fun2(new Date(new Date().setDate(new Date().getDate())));
            }
            else {
                model.mxList.clear();
            }
        }

        avalon.ready(function () {
            //获取页面宽度和高度
            fwidth = document.documentElement.clientWidth;
            fheight = document.documentElement.clientHeight;

            var lg = $.loading({
                content: '加载中...',
            })
            //加载时间控件
            //fun1(new Date(new Date().setDate(new Date().getDate())));
            //fun2(new Date(new Date().setDate(new Date().getDate())));
            //model.ctData.StartTime = $("#djsj").val();
            //model.ctData.EndTime = $("#jssj").val();
            //获取督办类别
            $.getJSON('/API/VIEWAPI.ashx?Action=XTGL_GETZIDIANLIST&r=' + Math.random(), { P1: 2 }, function (resultData) {
                lg.hide();
                if (resultData.ErrorMsg == "") {
                    model.lbData = resultData.Result;
                    if (resultData.Result.length > 0) {
                        model.ctData.LeiBie = resultData.Result[0].ID;
                    }
                }
                else {
                    $.tips({
                        content: "督办类别加载失败",
                        stayTime: 2000,
                        type: "warn"
                    })
                }

            })

            $("#iframef").attr("src", "/View_Mobile/UI/UI_PERSON.html?r=" + Math.random() );

            //微信上传图片
            ComFunJS.uploadimg();
        })
        function back() {
            window.history.back();
        }
    </script>
    <style type="text/css">
        .ui-select {
            border: none;
            border: 0;
            background-color: #fff;
            appearance: none;
            -moz-appearance: none; /* Firefox */
            -webkit-appearance: none; /* Safari 和 Chrome */
        }

        .ms-controller, [ms-controller] {
            display: none;
        }

        .ui-form-item .wspan {
            width: 100%;
            display: -webkit-box;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            -webkit-appearance: none;
            border: 0;
            background: 0 0;
            padding-left: 95px;
        }

            .ui-form-item .wspan img {
                width: 50px;
                height: 50px;
                padding-right: 3px;
            }

        .sctp {
            color: #18b4ed;
            right: 4px;
            top: -5px;
            z-index: 9;
            width: 20px;
            height: 20px;
            background: #fff;
            border-radius: 13px;
            line-height: 20px;
            text-indent: -3px;
            position: absolute;
            font-size: 25px;
        }

        .imgxl {
            position: relative;
            float: left;
            padding-top: 0;
            height: 50px;
            width: 50px;
            padding-right: 10px;
            margin-left: 0px;
            margin-bottom: 5px;
        }

        .tpxs {
            height: 50px;
            width: 50px;
            position: absolute;
            top: 0;
            left: 0;
            z-index: 1;
            background-repeat: no-repeat;
            -webkit-background-size: cover;
        }
    </style>
    <title>发布任务</title>
</head>
<body ms-controller="rwmodel">
    <div id="content">
        <div class="ui-footer ui-footer-stable ui-btn-group ui-border-t">
            <button class="ui-btn-lg ui-btn-primary" ms-click="savedata()">
                发布任务
            </button>
        </div>
        <section class="ui-container">
            <div class="ui-form ui-border-t">
                <div class="ui-form-item ui-border-b" >
                    <label>
                        督办人
                    </label>
                    <span style="padding-left: 95px;text-align:justify" >{{ComFunJS.convuser(ctData.RWFZR)}}</span>

                </div>
                <div class="ui-form-item ui-border-b">
                    <label>
                        督办类别
                    </label>
                    <div class="ui-select ui-border-b">
                        <select ms-duplex="ctData.LeiBie">
                            <option ms-repeat-item="lbData" ms-attr-value="item.ID">{{item.TypeName}}</option>
                        </select>
                    </div>
                </div>
                <!--<div class="ui-form-item ui-border-b">
                    <label>
                        发车时间
                    </label>
                    <div class="ui-select ui-border-b">
                        <input type="text" placeholder="请输入发车时间" ms-duplex="ctData.StartTime" id="kssj" style="padding-left:0" />
                    </div>
                </div>-->
                <div class="ui-form-item ui-border-b">
                    <label>
                        任务标题
                    </label>

                    <input type="text" placeholder="请输入任务标题" ms-duplex="ctData.RWTitle" />
                </div>
                <div class="ui-form-item ui-border-b">
                    <label>
                        提醒
                    </label>
                    <label class="ui-switch" style="padding-left: 95px; right: auto; ">
                        <input type="checkbox" ms-duplex-radio="ctData.IsTX"  />
                    </label>
                    <span style="margin-left:147px;font-size:12px">(完成时间当天提醒)</span> 
                </div>
                <div class="ui-form-item ui-border-b" style="height:auto">
                    <label>
                        负责人
                    </label>
                    <div class="ui-txt-muted ui-whitespace ui-form-item-link" style="padding-left: 95px;text-align:justify" id="rw_fzry" ms-click="selperson()">请选择负责人</div>
                </div>
                <div class="ui-tab" ms-if="mxList.size()">
                    <ul class="ui-tab-nav ui-border-b">
                        <li class="current">任务明细({{mxList.size()}})</li>
                        <li class=""></li>
                        <li class=""></li>
                    </ul>
                </div>
                <!--<div class="ui-form-item ui-border-b">
                    <label>
                        任务明细
                    </label>
                    <span class="wspan">共 {{mxList.size()}} 条</span>
                </div>-->
                <div class="ui-form ui-border-t">
                    <ul class="ui-list ui-list-pure">
                        <li class="ui-border ui-label-list" ms-repeat-el="mxList" style=" padding: 0; margin-top: 10px; margin-bottom: 10px;">
                            <div class="ui-form-item ui-border-b" style="height:auto">
                                <label>
                                    负责人
                                </label>
                                <span style="padding-left: 95px;text-align:justify">{{ComFunJS.convuser(el.RWUSER)}}</span>
                                <a class="ui-btn-lg ui-btn-primary" ms-click="fzrw(el)" style="float: right; width: auto; height: 30px; line-height: 30px; margin-top: 7px; margin-left: 5px;">复制</a>
                            </div>
                            <div class="ui-form-item ui-border-b">
                                <label>
                                    任务内容
                                </label>
                                <input type="text" placeholder="请输入任务内容" ms-duplex="el.RWContent" />
                            </div>
                            <div class="ui-form-item ui-border-b">
                                <label>
                                    完成时间
                                </label>
                                <div class="ui-select ui-border-b">
                                    <input type="text" placeholder="请输入完成时间" ms-duplex="el.RWEDate" class="wcsj" style="padding-left:0" />
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>

                <!--<div class="ui-form-item ui-border-b" style="height:auto;min-height:44px">
                    <label>
                        上传图片
                    </label>

                    <div class="wspan" style="padding-top: 5px; height: auto;display:block">
                        <ul id="imglist">
                            <li class="imgxl scli"><img id="add_pit" src="/View_Mobile/Images/icon-add.png" /></li>
                        </ul>
                        <div style="clear:both"></div>
                    </div>
                </div>-->
            </div>
        </section>
    </div>

    <iframe id="iframef" src="" style="display: none; margin-bottom: -7px;" frameborder="0"></iframe>

</body>
</html>
